<?
/*********************************************
 *1626职位列表
 * *******************************************/
function smarty_function_qishi_jobs_list($params, &$smarty)
{
	extract($params);
	global $db;
	$paged = (NULL != $paged) ? $paged : 0; //是否分页显示
	$row = (NULL != $row) ? $row : 15; //默认显示记录数量
	$start  = (NULL != $start) ? $start : 0; //从第几条开始读取，缺省0
	$jobslen = (NULL != $jobslen) ? $jobslen : 7; //默认职位程度
	$companynamelen = (NULL != $companynamelen) ? $companynamelen : 15; //默认公司名称长度
	$dot = (NULL != $dot) ? $dot : ''; //默认截取后填补字符
	$listname = (NULL != $listname) ? $listname : "list"; //默认的section名称
	$wheresql=" WHERE audit='1' AND display='1'";
	$jobids?$wheresql.=" AND id in(".implode(',',$jobids).") ":'';//指定jobid
	$category?$wheresql.=" AND category='".intval($category)."' ":'';//大类
	$subclass?$wheresql.=" AND subclass='".intval($subclass)."' ":'';//小类
	
	//地區重新處理
	$district=intval($district);
	if($district){
		if($district==100){ //全香港
			$wheresql.=" AND district>=100 AND district <600";//地区
		}
		elseif($district % 100 == 0){//指定區塊
			$wheresql.=" AND district>='".$district."' AND district <'".($district + 100)."'";//地区
		}		
		else{//專區
			$wheresql.=" AND district='".$district."' ";//地区
		}
	}
	
	$trade?$wheresql.=" AND trade='".intval($trade)."' ":'';//行业
	$salary_type?$wheresql.=" AND jobs_wage_per='".intval($salary_type)."' ":'';//薪金計算
	$enroll_type?$wheresql.=" AND jobs_employ_type='".intval($enroll_type)."' ":'';//聘用形式
	$settr?$settr_val=strtotime("-".$settr." day"):'';
	$settr?$wheresql.=" AND refreshtime>".$settr_val."":'';//时间范围
	$education?$wheresql.=" AND jobs_education='".intval($education)."' ":'';//学历
	$experience?$wheresql.=" AND experience='".intval($experience)."' ":'';//工作经验
	$wage?$wheresql.=" AND jobs_wage_from>='".intval($wage)."' ":'';//薪资待遇
	$wageto?$wheresql.=" AND jobs_wage_to<='".intval($wageto)."' ":'';//薪资待遇
	$nature?$wheresql.=" AND jobs_nature='".intval($nature)."' ":'';//职位性质
	$outdated?$wheresql.=" AND deadline>'".time()."' ":'';//只显示有效信息，
	$key=trim($key);
	!empty($key)?($wheresql .=" AND  jobs_name_cn like '%". mysql_like_quote($key)."%'"):'';//职位关键字
	//排列字段d
	$orderby=ereg('refreshtime|addtime|id',$orderby)?$orderby:"refreshtime";
	//显示顺序
	$displayorder=ereg('asc|desc',$displayorder)?$displayorder:"DESC";
	//sql语句
	$orderbysql=" ORDER BY ".$orderby." ".$displayorder;
	if ($paged=="1")
	{
		require_once(QISHI_ROOT_PATH.'include/page.class.php');
		$total_sql="SELECT COUNT(*) AS num FROM ".table('jobs').$wheresql;
		$total_count=get_total($total_sql);
		$page = new page(array('total'=>$total_count, 'perpage'=>$row));
		//----------
		$currenpage=$page->nowindex;
		$offset=($currenpage-1)*$row;
		if ($total_count>$row)
		{
			$smarty->assign('page',$page->show(3));//分页符
		}
	}
	///
	$offset=$offset?$offset:0;
	$offset=$start>0?$start:$offset;
	$limit=" LIMIT ".$offset.','.$row;
	/////
	if(isset($key_type) && $key_type == 2)
	{
		$result = $db->query("SELECT * FROM ".table('jobs')." WHERE id = ". floatval($key));
	}else{
		$result = $db->query("SELECT * FROM ".table('jobs')." ".$wheresql.$orderbysql.$limit);
	}
	while($row = $db->fetch_array($result))
	{
		$company=get_company_profile($row['uid']);
		$wage=get_jobs_wage_one($row['wage']);
		$education=get_jobs_education_one($row['jobs_education']);
		$district=get_jobs_area_one($row['district']);
		$row['jobs_name']=cut_str($row['jobs_name_cn'],$jobslen,0,$dot);
//		$row['jobs_name']=cut_str($row['jobs_name'],$jobslen,0,$dot);
		$row['companyname']=cut_str($row['jobs_boss'],$companynamelen,0,$dot);
//		$row['companyname']=cut_str($company['companyname'],$companynamelen,0,$dot);
		$row['company_recommend']=$company['recommend'];
		$row['wage']=$wage['categoryname'];
		$row['education']=$education['categoryname']?$education['categoryname']:'不限';
		$row['district']=$district['categoryname'];
		$row['jobid']=$row['id'];
		$row['refreshtime']=date('Y-m-d',$row['refreshtime']);
		$row['jobs_url']=url_rewrite('jobs-show',array('id0'=>$row['id']));
		$row['company_url']=url_rewrite('company',array('id0'=>$company['id']));
		
		if($act=='compare'){
		//比較專用
		$jobsnature=get_jobs_nature_one($row['nature']);//职位性质
		$row['jobsnature']=$jobsnature['categoryname'];
		
		$experience=get_jobs_experience_one($row['experience']);//工作经验
		$row['experience']=$experience?$experience['categoryname']:'不限';
		
		$profile=get_company_profile($row['uid']);//企业介绍
		$trade=get_jobs_trade_one($profile['trade']);//获取行业
		$scale=get_jobs_scale_one($profile['scale']);//公司规模
		$area=get_jobs_area_one($profile['area']);//所在地区
		$nature=get_jobs_corporation_one($profile['nature']);//企业性质
		$row['trade']=$trade['categoryname'];
		$row['scale']=$scale['categoryname'];
		$row['nature']=$nature['categoryname']?$nature['categoryname']:'未填';
		$row['area']=$area['categoryname'];		
		}
		$List[] = $row;
	}
	$smarty->assign($listname, $List);
	unset($List);
}
?>